//
//  UIButton+Extension.swift
//  weibo
//
//  Created by 吴婷婷 on 15/11/4.
//  Copyright © 2015年 wutingting. All rights reserved.
//

import UIKit

extension UIButton {
    ///'便利'构造函数
    convenience init(imageName: String, backImageName:String?) {
        
        self.init()
        
        setImage(UIImage(named:imageName), forState: UIControlState.Normal)
        setImage(UIImage(named:imageName + "_highlighted"), forState: UIControlState.Highlighted)
        
        if let backImageName = backImageName {
            setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
            setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: UIControlState.Highlighted)
        }
        
        sizeToFit()
        
    }
    
    convenience init(title: String, backImageName: String, color: UIColor){
        
        self.init()
        
        setTitle(title, forState: .Normal)
        
        setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
        setTitleColor(color, forState: .Normal)
        
        sizeToFit()
        
    }
    
    convenience init(title: String,fontSize: CGFloat ,ImageName: String, color: UIColor){
        
        self.init()
        
        setTitle(title, forState: .Normal)
        setImage(UIImage(named: ImageName), forState: .Normal)
        setTitleColor(color, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        
        sizeToFit()
        
    }
    
    convenience init(title: String,fontSize: CGFloat ,ImageName: String?, color: UIColor,backColor: UIColor){
        
        self.init()
        
        setTitle(title, forState: .Normal)
        if let ImageName = ImageName{
            setImage(UIImage(named: ImageName), forState: .Normal)
        }
        setTitleColor(color, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        backgroundColor = backColor
        
        sizeToFit()
    }
    
    
}
